home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
synth_studies
/
resgrep03b
/
source
/
settings.cc
< prev
next >
Wrap
C/C++ Source or Header
|
1999-09-15
|
3KB
|
139 lines
//
// Load and Save settings
//
extern "C" {
#include <stdio.h>
#include <stdlib.h>
char *strdup(char *);
};
#include "export.h"
#include "resgrep.h"
#include "utils.h"
#define MAGIC_TEXT "ResGrepSettingsFile"
static char *SettingsFileName="ResGrep:etc/settings";
extern list *conversions;
void freeconvert(list *c)
{
while( c->getfirst()->getsucc()!=NULL )
delete c->remhead();
return;
}
void savesettings(void)
{
FILE *out;
convert *n;
if( (out=fopen(SettingsFileName,"w"))==NULL )
{
ResError("Can't open file to\nwrite settings to.");
return;
}
fprintf(out,"%s\n%d\n%d\n",MAGIC_TEXT,VERSION,REVISION);
for(n=(convert *)conversions->getfirst();((node *)n)->getsucc();((node *)n)=n->getsucc())
fprintf(out,"###\n%s\n%s\n%s\n%d\n%d\n%s\n%d\n%d\n",
pack2cstr(n->getpack()),n->getname(),n->command,
n->isARexx,n->sendto,n->filename,n->builtin,
n->funcnum);
fprintf(out,"!!!\n");
fclose(out);
return;
}
void savesettingsas(void)
{
savesettings();
return;
}
void skipnewline(char *s)
{
if( strlen(s)<=0 )
return;
if( s[strlen(s)-1]=='\n' )
s[strlen(s)-1]='\0';
return;
}
void loadsettings(void)
{
FILE *in;
list *co=new list();
convert *c;
char buffer[1024];
if( (in=fopen(SettingsFileName,"r"))==NULL )
{
ResError("Can't open setting file.");
return;
}
fgets(buffer, 1024, in);
skipnewline(buffer);
if( strcmp(buffer,MAGIC_TEXT)!=NULL )
{
ResError("Setting file corrupted.");
return;
}
fgets(buffer, 1024, in);
if( atoi(buffer)>VERSION )
{
ResError("Version in setting file to small.");
return;
}
fgets(buffer, 1024, in);
if( atoi(buffer)>REVISION )
ResWarning("Revision in setting file to small.");
fgets(buffer, 1024, in);
skipnewline(buffer);
while( !feof(in) && strcmp(buffer,"###")==0 )
{
char Cpack[7], Cname[1024], Ccommand[1024], CisARexx[5], Csendto[5];
char Cfilename[1024], Cbuiltin[5], Cexport[7];
fgets(Cpack, 7, in);
skipnewline(Cpack);
fgets(Cname, 1024, in);
skipnewline(Cname);
fgets(Ccommand, 1024, in);
skipnewline(Ccommand);
fgets(CisARexx, 5, in);
skipnewline(CisARexx);
fgets(Csendto, 5, in);
skipnewline(Csendto);
fgets(Cfilename, 1024, in);
skipnewline(Cfilename);
fgets(Cbuiltin, 5, in);
skipnewline(Cbuiltin);
fgets(Cexport, 7, in);
skipnewline(Cexport);
/*printf("%08lx %d '%s' '%s' %d %d '%s' %d\n",
cstr2pack(Cpack), atoi(Cexport), Cname, Ccommand,
(bool)atoi(CisARexx), (send)atoi(Csendto),
Cfilename, (bool)atoi(Cbuiltin) );
*/
co->addtail( new convert (
cstr2pack(Cpack), atoi(Cexport), (char *)strdup(Cname), Ccommand,
(bool)atoi(CisARexx), (send)atoi(Csendto),
Cfilename, (bool)atoi(Cbuiltin)) );
fgets(buffer, 1024, in);
skipnewline(buffer);
}
if( strcmp(buffer,"!!!")!=0 )
{
ResError("Setting file corrupted.");
freeconvert(co);
return;
}
freeconvert(conversions);
conversions = co;
fclose(in);
return;
}